<template>
    <div class="contact-futrue">
        <div class="font-24 text-grey mb-24">{{ $t('交割时间') }}</div>
        <ul class="flex flex-wrap w-full">
            <li v-for="(item, index) in initFutrue.para" :key="item.para_id" class="h-92 flex items-center mb-22"
                @click="onSelect(item, index)">
                <p class="w-95 h-full flex justify-center items-center font-22 flex-1"
                    :class="active === item.para_id ? 'bg-light-blue text-white' : 'bgDark textColor'">{{ item.time_num +
                        item.time_unit.substr(0, 1) }}</p>
                <p class="w-125 h-full flex justify-center items-center font-22 flex-1"
                    :class="active === item.para_id ? 'bg-dark-blue text-white' : 'contBackground textColor'">{{
                        handleString(item.profit_ratio) }}%</p>
            </li>
        </ul>
    </div>
</template>

<script>
export default {
    name: 'ContractFutrue',
    props: {
        initFutrue: {
            type: Object,
            default() {
                return {}
            }
        }
    },
    data() {
        return {
            active: '',
            initParam: [] // 初始化参数
        }
    },
    created() {
        this.active = this.initFutrue && this.initFutrue.para ? this.initFutrue.para[0].para_id : ''
        this.$emit('paraId', { id: this.active, index: 0 })
    },
    methods: {
        //交割合约百分比显示修改，数字一致时只显示其中一个，不一致时显示范围
        handleString(str){
            const parts = str.split('~');
            const leftNum = parseInt(parts[0]);
            const rightNum = parseInt(parts[1]);
            if (leftNum === rightNum) {
                return leftNum;
            } else {
                return str;
            }            
        },
        onSelect(item, index) { // 选中
            this.active = item.para_id
            this.$emit('paraId', { id: this.active, index })
        }
    }
}
</script>
<style scoped lang="scss">
.bgDark {
    @include themify() {
        background: themed("tab_background2");
    }
}

.bg-light-blue {
    background: #1D91FF;
}

.bg-dark-blue {
    background: #1255A3;
}
</style>
